#include "EventHandler.h"
#include "Game.h"
#include "SDL.h"
#include "Screen.h"
#include <algorithm>

//base class implementation of HandleEvent
//having SDL_Quit here means only one event handler needs to be active for
//the user to quit.
void EventHandler::HandleEvent(SDL_Event* Event)
{
	switch (Event->type)
            {
			case SDL_QUIT:
                {
				    TheGame::Instance()->Quit();
                    break;  
                }
			case SDL_KEYDOWN:
                {
                    OnKeyBoardDownEvent(Event->key);
                    break;
                }
			case SDL_KEYUP:
                {
				    OnKeyBoardUpEvent(Event->key);
				    break;
                }

			case SDL_JOYAXISMOTION:
                {
				    OnJoystickAxisEvent(Event->jaxis);
				    break;
                }

            case SDL_JOYBUTTONDOWN:
            case SDL_JOYBUTTONUP:
                {
                    OnJoyButtonEvent(Event->jbutton);
                    break;
                }
            case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEBUTTONDOWN:
                {
				    OnMouseButton(Event->button);
                    break;
                }
            case SDL_MOUSEMOTION:
                {
                    OnMouseMotion(Event->motion);
                    break;
                }
            case SDL_VIDEORESIZE : 
                {
                    OnResizeEvent(Event->resize);
                    break;
                }
        }
}

void EventHandler::OnResizeEvent(const SDL_ResizeEvent& Event)
{
    TheScreen::Instance()->UpdateScreenSize(Event.h, Event.w);
}
